package snapex;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

@Configuration
//@Conditional(JdbcCondition.class)
@AutoConfigureAfter(EncryptablePropertiesConfiguration.class)
public class MybatisConfiguration {

	@Autowired
	private DataSource dataSource;
	
	@Bean
	public DataSourceTransactionManager transactionManager() {
	  return new DataSourceTransactionManager(dataSource);
	}
		
//	static class JdbcCondition extends SpringBootCondition{
//
//		@Override
//		public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
//	
//			ConditionMessage.Builder message = ConditionMessage.forCondition("spring.datasource Condition");
//			
//			String datasource = context.getEnvironment().getProperty("spring.datasource");
//			if(StringUtils.isNotEmpty(datasource)) {				
//				return ConditionOutcome.match(message.foundExactly("spring.datasource"));
//			}
//			return ConditionOutcome.noMatch(message.didNotFind("spring.datasource").atAll());
//		}	
//	}
}
